﻿@{
    ViewData["Title"] = "添加或修改用户";
   
        Layout = "~/Views/Shared/_Layout.cshtml";
}
@model User
@section css{
    <style>
        .layui-form-item .layui-input {
            width: 350px;
            padding-right: 10px;
            line-height: 38px;
        }

        .layui-form-item .layui-textarea {
            width: 350px;
        }
    </style>
}
<form class="layui-form" action="" lay-filter="user-edit">
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form">
                @if (Model.Id > 0)
                {
                    <div class="layui-form-item">
                        <label class="layui-form-label">编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="id" lay-verify="id" value="@Model.Id" disabled class="layui-input">
                        </div>
                    </div>
                }
                <div class="layui-form-item">
                    <label class="layui-form-label required">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="@Model.Name" lay-verify="required" lay-reqtext="账号不能为空" placeholder="请输入用户账号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">真实姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="trueName" value="@Model.TrueName" lay-verify="required" lay-reqtext="真实姓名不能为空" placeholder="请输入真实姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" value="@Model.Password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">手机</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" lay-verify="required" value="@Model.Mobile" lay-reqtext="手机不能为空" placeholder="请输入手机" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">邮箱</label>
                    <div class="layui-input-block">
                        <input type="email" name="email" lay-verify="required" value="@Model.Email" placeholder="请输入邮箱" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label required">备注信息</label>
                    <div class="layui-input-block">
                        <textarea name="remark" lay-verify="required" class="layui-textarea" value="@Model.Remark" placeholder="请输入备注信息"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
@section js{
    <script>
            layui.use(['form', 'common'], function () {
                var form = layui.form,
                    apiUtil = layui.common;
                /**
                 * 初始化表单，要加上，不然刷新部分组件可能会不加载
                 */
                // 当前弹出层，防止ID被覆盖
                var parentIndex = parent.layer.getFrameIndex(window.name);

                var id=@Model.Id;
                //var user = apiUtil.getCurrentUser();
                form.render();
                //监听提交
                form.on('submit(saveBtn)', function (data) {
                    if (data.field.id>0) {
                        apiUtil.ajax('user/modify', data.field, "application/json", "post", function (res) {
                            if (res.statusCode == 200 && res.success == true) {
                                apiUtil.success(res.msg);
                                parent.layer.close(parentIndex);
                            } else {
                                apiUtil.error(res.msg);
                            }
                        });
                    } else {
                        apiUtil.ajax('user/register', data.field, "application/json", "post", function (res) {
                            if (res.statusCode == 200 && res.success == true) {
                                apiUtil.success(res.msg);
                                parent.layer.close(parentIndex);
                            } else {
                                apiUtil.error(res.msg);
                            }
                        });
                    }
                    return false;
                });
            });

    </script>
}